//
//  AnnouncementTableViewCell.m
//  CaiPiao
//
//  Created by apple on 2018/5/16.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "AnnouncementTableViewCell.h"

@implementation AnnouncementTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//EndTime = "2018/05/13";
//HTeam = "";
//ID = 950227;
//IssueName = 2018067;
//LotteryID = 11;
//LotteryName = "\U80dc\U8d1f\U5f69";
//QuickFlag = 0;
//RValue = "";
//Rz = "0,3,0,3,3,3,0,0,3,3,1,1,1,0";
//VTeam = "";
//WinNumber = "0,3,0,3,3,3,0,0,3,3,1,1,1,0";

-(void)setWinNumWith:(NSString*)winNumber{
    for (UIView* view in self.winNumBoxView.subviews) {
        [view removeFromSuperview];
    }
    NSArray* checkArray = [winNumber componentsSeparatedByString:@","];
    if ([checkArray count]>13) {
        for (int i=0; i<[checkArray count]; i++) {
            UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(i*(12+6), 10, 12, 25)];
            numberView.backgroundColor = [UIColor colorWithRed:33/255.0 green:172/255.0 blue:109/255.0 alpha:1];
            numberView.clipsToBounds = YES;
            numberView.layer.cornerRadius = 2;
            
            
            UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 12, 25)];
            numberLabel.font = [UIFont boldSystemFontOfSize:15];
            numberLabel.textColor = [UIColor whiteColor];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.text = [checkArray objectAtIndex:i];
            
            [numberView addSubview:numberLabel];
            [self.winNumBoxView addSubview:numberView];
        }
        return;
    }
    NSArray* winNumberArray = [winNumber componentsSeparatedByString:@"+"];
    if ([winNumberArray count]>0) {
        NSArray* redArray;
        NSArray* blueArray;
        
        NSString* redString = [winNumberArray objectAtIndex:0];
        if ([redString rangeOfString:@","].location == NSNotFound) {
            redArray = [redString componentsSeparatedByString:@" "];
        }else{
            redArray = [redString componentsSeparatedByString:@","];
        }
        if ([winNumberArray count]>1) {
            NSString* blueString = [winNumberArray objectAtIndex:1];
            if ([blueString rangeOfString:@","].location == NSNotFound) {
                blueArray = [blueString componentsSeparatedByString:@" "];
            }else{
                blueArray = [blueString componentsSeparatedByString:@","];
            }
        }
        float spacingX = 0;
        for (int i=0; i<[redArray count]; i++) {
            UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(i*(25+5), 10, 25, 25)];
            numberView.backgroundColor = [UIColor colorWithRed:(255.0/255.0) green:(90/255.0) blue:0 alpha:1];
            UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
            numberLabel.font = [UIFont boldSystemFontOfSize:15];
            numberLabel.textColor = [UIColor whiteColor];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.text = [redArray objectAtIndex:i];
            [numberView addSubview:numberLabel];
            numberView.layer.cornerRadius = 25*0.5;
            [self.winNumBoxView addSubview:numberView];
            spacingX+=(25+5);
        }
        
        for (int i=0; i<[blueArray count]; i++) {
            UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(spacingX, 10, 25, 25)];
            numberView.backgroundColor = [UIColor colorWithRed:(69.0/255.0) green:(160/255.0) blue:(255.0/255.0) alpha:1];
            UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
            numberLabel.font = [UIFont boldSystemFontOfSize:15];
            numberLabel.textColor = [UIColor whiteColor];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.text = [blueArray objectAtIndex:i];
            [numberView addSubview:numberLabel];
            numberView.layer.cornerRadius = 25*0.5;
            [self.winNumBoxView addSubview:numberView];
            spacingX+=(25+5);
        }
    }
    
}
//VTeam主队
//EndTime = "2018/05/16";
//HTeam = "\U79d1\U6d1b\U79d1\U6d1b";
//ID = 955299;
//IssueName = 20180515;
//LotteryID = 1;
//LotteryName = "\U7ade\U5f69\U8db3\U7403";
//QuickFlag = 0;
//RValue = "-1";
//Rz = "2:0";
//VTeam = "\U73bb\U5229\U74e6\U5c14";
//WinNumber = "";

-(void)setTeamWith:(NSDictionary*)dic{
    for (UIView* view in self.winNumBoxView.subviews) {
        [view removeFromSuperview];
    }
    UIView* boxView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, 250, 25)];
//    boxView.backgroundColor = [UIColor orangeColor];
    boxView.layer.cornerRadius = 12;
    UILabel* teamLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 250, 25)];
    teamLabel.font = [UIFont boldSystemFontOfSize:15];
    teamLabel.textColor = [UIColor whiteColor];
    teamLabel.textAlignment = NSTextAlignmentCenter;
    teamLabel.text = [NSString stringWithFormat:@"%@ %@ %@",dic[@"HTeam"],dic[@"Rz"],dic[@"VTeam"]];
    
    if([dic[@"LotteryID"] integerValue]==1){
        //33 172 109
        boxView.backgroundColor = [UIColor colorWithRed:33/255.0 green:172/255.0 blue:109/255.0 alpha:1];
    }else{
        boxView.backgroundColor = [UIColor colorWithRed:255/255.0 green:165/255.0 blue:59/255.0 alpha:1];
    }
    
    
    [boxView addSubview:teamLabel];
    [self.winNumBoxView addSubview:boxView];
}

@end
